package com.hoopchina.ui.download;

import java.util.ArrayList;
import com.hoopchina.news.R;
import com.hoopchina.data.ListBaseAdapter;
import com.hoopchina.util.LogUtils;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

class DownloadListAdaptor extends ListBaseAdapter {
    
    public DownloadListAdaptor( Context aContext, ArrayList<?> aData ) {
        super( aContext, aData );
        LogUtils.d( "constructor");
        mResource = R.layout.downloadview_listitem;
    }

    class ListItemHolder {
        ProgressBar mProgressBar;
        TextView    mType;
        TextView    mPercent;
        TextView    mCounter;
    }

    @Override
    public View getView( final int position, View convertView, ViewGroup parent ) {
        ListItemHolder holder = null;
        DownloadItem item = (DownloadItem)mData.get( position );
        if ( convertView == null ) {
            convertView = mLayoutInflater.inflate( mResource, null );
            holder = new ListItemHolder();
            holder.mProgressBar = ( ProgressBar ) convertView.findViewById( R.id.listitem_line2_pb );
            holder.mType = ( TextView ) convertView
                    .findViewById( R.id.listitem_line1_txtcontent );
            holder.mPercent = ( TextView ) convertView.findViewById( R.id.listitem_line2_percent );
            holder.mCounter = (TextView) convertView.findViewById( R.id.listitem_line1_txtcontent );
            convertView.setTag( holder );
        }
        else {
            holder = ( ListItemHolder ) convertView.getTag();
        }
        holder.mType.setText( item.getType() );
        holder.mPercent.setText( item.getProgress()+"%" );
        holder.mProgressBar.setProgress( item.getProgress() );
        holder.mCounter.setText( " "+item.getType()+"  ("+item.getDoneNum()+"/"+item.getTotalNum()+")" );
            
        return convertView;
    }
}